// 加载图片
function loadImg(src) {
  let promise = new Promise((resolve, reject) => {
    let img = document.createElement("img");
    img.onload = function () {
      resolve(img);
    };
    img.onerror = function () {
      reject("图片加载失败");
    };
    img.src = src;
  });
  return promise;
}
let src = "https://www.imooc.com/static/img/index/logo_new.png";
let result = loadImg(src);

// 加载后的处理
result
  .then(function (img) {
    // part1
    console.log("img.width:", img.width);
    return img;
  })
  .then(function (img) {
    // part2
    console.log("img.height:", img.height);
    return img;
  })
  .then(function (img) {
    // part3
    // 新增业务逻辑
    console.log("img.src:", img.src);
  })
  .catch(function (ex) {
    // 统一捕获异常
    console.log(ex);
  });
